<!doctype html>
<html>
<head>
    <meta charset="UTF-8" />
    <title>确认订单</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/Wx/css/base.css" />
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/Wx/css/detail.css" />
</head>
<body>
<div class="detail" style="padding-top:50px;display: none">
    <div id="header">
        <a href="javascript:0;" class="go_history">返回</a>
        <div class="title">选择收货地址</div>
        <span onClick="window.location='__MODULE__/MyAddress/index'">管理</span>
    </div>
    <div class="choose">
        <ul>
            <volist name="address" id="ad">
                <li onclick="edit_address(this)">
                    <h2><span>{$ad.name}</span><b>{$ad.mobile}</b></h2>
                    <p><b><?=$ad['is_default']>0?"[默认地址]":'';?></b><?=getarea($ad['a_id_1']).getarea($ad['a_id_2']).getarea($ad['a_id_3']);?>{$ad.content}</p>
                </li>
                <!--<li>-->
                    <!--<h2><span>龚迁田</span><b>15994242356</b></h2>-->
                    <!--<p>广东省深圳市宝安区西乡街道宝安区西乡盐田结算到-->
                        <!--田街道宝源公寓F321</p>-->
                <!--</li>-->
                <!--<li>-->
                    <!--<h2><span>龚迁田</span><b>15994242356</b></h2>-->
                    <!--<p>广东省深圳市宝安区西乡街道宝安区西乡盐田结算到-->
                        <!--田街道宝源公寓F321</p>-->
                <!--</li>-->
            </volist>
        </ul>
    </div>
    <!--<div class="button"><input type="button" value="新增地址" onClick="window.location='address.html'"/></div>-->
</div>
<div class="prodetail">
    <if condition="$address">
        <div class="address">
            <div class="add">
                <a href="javascript:0;">
                    <volist name="address" id="ad" offset="0" length='1'>
                        <h3><span class="address_name">{$ad.name}</span><span class="address_mobile">{$ad.mobile}</span></h3>
                        <p class="address_content">收货地址：<?=getarea($ad['a_id_1']).getarea($ad['a_id_2']).getarea($ad['a_id_3']);?>{$ad.content}</p>
                    </volist>
                </a>
            </div>
        </div>
        <else />
        <!--未填写地址-->
        <div class="address">
            <a href="javascript:0;"><span>添加收货人信息</span></a>
        </div></if>
    <volist name="wholesale"  id="vo">
        <div class="prolist" g_u_id="{$key}">
            <volist name="vo['wholesale']" id="sg">
                <div class="pro" wid="{$sg.id}" onclick="window.location.href='__MODULE__/Wholesale/prodetail/id/{$sg.g_id}'">
                    <div class="pic"><img src="<?=isMorePic($sg['spellgroup']['h_imgs'])?>"/></div>
                    <div class="name">
                        <h2>{$sg.spellgroup.title} {$sg.spellgroup.u_num}<?=getunit($sg['spellgroup']['unit'])?></h2>
                        <p><b><img src="{$vo.member.avatar}"/></b><i>{$vo.member.nickname}</i><em>{$vo.village}</em></p>
                        <h3><del>原价：{$sg.spellgroup.price}</del><em>￥{$sg.price}</em><i>（{$sg.price_range.start}-{$sg.price_range.end}件）</i><b>X{$sg.num}</b></h3>
                    </div>
                </div>
            </volist>
        </div>
        <!--<div class="number-pf">购买数量<span class="num"><s class="reduce" onClick="ChangeNumber(-1)">-</s><input type="text" id="Number" value="1" class="Number"/><s class="Add" onClick="ChangeNumber(1)">+</s></span></div>-->
        <div class="deliver" style="margin-top: 10px;">配送方式<span>快递￥10</span><span style="display:none;">快递免邮</span></div>
        <div class="message02">买家留言:<input type="text" class="wholesale_content" value="{$vo['wholesale'][0]['content']}" placeholder="选填：可填写您对买家的要求"/></div>
        <div class="total">共<b><?=count($vo['wholesale'])?></b>件商品<span>合计：<i>￥{$vo.price_all}</i></span></div>
    </volist>
    <div class="sure">
        <p style="font-size:12px;">应付金额：<em style="font-size:12px;" class="price_all"></em><b>（3%服务费）</b></p>
        <input type="submit" value="提交订单" onClick="pay_order()" style="width:28%;"/>
    </div>
    <div class="expressfee">
        <div class="express">
            <h2>配送方式</h2>
            <p><span>快递￥10</span></p>
            <h3>关闭</h3>
        </div>
    </div>
</div>
<script  src="__PUBLIC__/Wx/js/jquery-1.9.1.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        var wid = new Array();
        $("div.pro").each(function(){
            wid.push($(this).attr('wid'));
        });//end each

        $.post("__MODULE__/Wholesale/editshopping",{'op':'price','wid':wid},function (price) {
            // console.log(price);
            var text = "￥"+price.all;

            if (price.all != 0){
                text += '+￥'+price.charge;
            }//end if

            $("em.price_all").text(text);
        });//end post
        // $(".ok b").text(d.num);
    });

    //更换地址
    function edit_address(obj) {
        var username = $(obj).children('h2').children('span').text();
        var mobile = $(obj).children('h2').children('b').text();
        var address = "收货地址："+$(obj).children('p').text().replace('[默认地址]',"");

        $(".address_name").text(username);
        $(".address_mobile").text(mobile);
        $(".address_content").text(address);

        $(".detail").css('display','none');
        $(".prodetail").css('display','block');
    }//end fun

    //生成订单
    function pay_order() {
        var name = $(".address_name").text();
        var mobile = $(".address_mobile").text();
        var address = $(".address_content").text().replace('收货地址：',"");
        var wid_pay = new Array();
        var state = 0;
        $("div.prolist").each(function () {
            var g_u_id = $(this).attr('g_u_id');
            var content = $(this).nextAll('div.message02').children('input.wholesale_content').val();
            var order_sn = 'PF'+"<?=date('YmdHis')?>"+Math.floor(Math.random()*99998+1);
            $(this).children('div.pro').each(function () {
                var wid = $(this).attr('wid');
                wid_pay.push($(this).attr('wid'));
                $.post("",{"g_u_id":g_u_id,"wid":wid,"content":content,"name":name,"mobile":mobile,"address":address,"order_sn":order_sn,"op":"order"},function (pi) {
                    // console.log(pi);
                    state = pi.state;
                    if(pi.state>0){
                        alert(pi.val);
                    }//end if
                });//end post
            });//end fun
        });//end fun

        if (state == 0){
            $.post("",{"wid_pay":wid_pay,"op":"pay"},function (pi) {
                // console.log(pi);
                if(pi.state>0){
                    alert(pi.val)
                }else{
                    window.location.href="http://www.xiangtws.com/index.php/Api/Salepay/choosePay/pay_id/"+pi.pay_id;
                }//end if
            });//end post
        }//end if
        // window.location.reload();
    }//end fun

    $(".address").click(function () {
        $(".prodetail").css('display','none');
        $(".detail").css('display','block');
    });

    $(".go_history").click(function () {
        $(".detail").css('display','none');
        $(".prodetail").css('display','block');
    });

    $('.deliver').click(function(){
        $('.expressfee').css('display','block')
    });
    $('.expressfee h3').click(function(){
        $('.expressfee').css('display','none')
    });
</script>
</body>
</html>